package com.btpn.infra.web.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;

import com.btpn.custody.dao.IUser;
import com.btpn.custody.entity.User;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class ChangePasswordInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = -267691653356971148L;
	
	@Autowired
	private IUser userDaoHibernate;
	
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
				
		User user = userDaoHibernate.get(SecurityContextHolder.getContext().getAuthentication().getName());
		if (user.isFirstLogin() & !invocation.getAction().getClass().getName().equals("com.btpn.custody.security.action.ChangePasswordAction")) {
			
			// changePasswordResult define at struts.xml - global
			return "changePasswordResult";
		}
		return invocation.invoke();
	}
}
